var updatePassword = {
	
	id:0,
	account:'',
		
	initPage:function(){
		updatePassword.id = util.getCookieValue("securId");
		updatePassword.initLoad(updatePassword.id);
		$("#confirmBtn").click(function(){
			updatePassword.saveOrupdate();
		});
		$("#update_Password").html(language.updatePassword[mainIndex.languageType]);
		$("#user_account").html(language.user_account[mainIndex.languageType]);
		$("#oldLoginPassword").html(language.oldLoginPassword[mainIndex.languageType]);
		$("#newLoginPassword").html(language.newLoginPassword[mainIndex.languageType]);
		$("#confirmBtn").html(language.confirmBtn[mainIndex.languageType]);
		$("#account").attr('placeholder',language.user_account[mainIndex.languageType]+"...");
		$("#password1").attr('placeholder',language.oldLoginPassword[mainIndex.languageType]+"...");
		$("#password2").attr('placeholder',language.newLoginPassword[mainIndex.languageType]+"...");
	},
	
	initLoad : function(id) {
		if(id && id!=0){
			usermanager.getUser({"userId":id},function(data){
				if(data.data && data.retCode == 0){
					var obj= data.data;
					updatePassword.account =  obj.account;
					$("#account").val(obj.account);
					$("#password1").val(obj.password);
					$("#account").attr("readOnly","true");
					$("#password1").attr("readOnly","true");
				}
			});
		}
	},
	
	saveOrupdate:function(){
		var account = $("#account").val();
		var oldLoginPassword = $("#password1").val();
		var newLoginPassword = $("#password2").val();
		if( account=='' || oldLoginPassword=='' || newLoginPassword==''){
			util.alertMessage(language.emptyParams[mainIndex.languageType]);
		}else if( oldLoginPassword==newLoginPassword ){
			util.alertMessage(language.samePassword[mainIndex.languageType]);
		}else{
			var params ={
					'account':account,
					'password':newLoginPassword,
					'userType':"2",
			};
			if(updatePassword.id){
				params['userId'] = updatePassword.id;
				if(params['account'] == updatePassword.account){
					params['account'] = '';
				}
			}
			usermanager.addOrUpdateUser(params,updatePassword.add_successcb,updatePassword.add_successcb);
		}
	},
	
	add_successcb:function(data){
		 if(data.retCode == 0){
			 layer.confirm(language.updateSuccess[mainIndex.languageType], {
				  title:language.systemtips[mainIndex.languageType],
				  btn: [language.confirm[mainIndex.languageType],language.cancel[mainIndex.languageType]]
				}, function(){
					location.href = 'login.html';
				});
		 }else if(data.retCode == -1){
			 util.alertMessage(language.existAccount[mainIndex.languageType]);
		 }
	},
		
}
updatePassword.initPage();